    //时
    var shi = 0;
    //分
    var fen = 0;
    //秒
    var miao = 0;
    var id1=0;
		var id2=0;
		var id3=0;
    var id4=0;
		var id5=0;
		var falseNum=0;
		var rightNum=0;
 		var rightlv=0; 
		var appleNum=2000;
		var speed=100;
		var winNum= 50;
		var suduNum=0
    var loseNum=50;
    //onkeydown事件
			window.onkeydown = function(event) { if(id5==1){ 
				var key = event.keyCode;} 
				var bg = document.getElementById("bg");
				for (i = 0; i < bg.children.length; i++) {
					var code = bg.children[i].getAttribute("keycode");
					if (key == code) {
						bg.removeChild(bg.children[i]);
						rightNum++;
						document.getElementById("right_score").innerHTML=rightNum;

          				
						rightlv=(rightNum/(rightNum+falseNum)).toFixed(2)*100;
						document.getElementById("right_parsent").innerHTML=rightlv;
						//根据正确的数量来确定每打对5个苹果往篮子里放一个苹果
					   switch(rightNum){
			case 5:
			document.getElementById("smallapple6").style.display="block";
			break;
			case 10:
			document.getElementById("smallapple5").style.display="block";
			break;
			case 15:
			document.getElementById("smallapple4").style.display="block";
			break;
			case 20:
			document.getElementById("smallapple3").style.display="block";
			break;
			case 25:
			document.getElementById("smallapple2").style.display="block";
			break;
			case 30:
			document.getElementById("smallapple1").style.display="block";
			break;
		}
					   if(rightNum==winNum){alert("恭喜您通关了！！！");
					   pause();
					   cancelAll();
					   id4=1;
					   }
						break;
						
					}
				}
			};
			//点击退出游戏
			function exit(){
				if(confirm("退出游戏？")){
					window.close()
				}
			};
			//清除苹果
			function clear_apple(){
				document.getElementById("smallapple1").style.display="none";
				document.getElementById("smallapple2").style.display="none";
				document.getElementById("smallapple3").style.display="none";
				document.getElementById("smallapple4").style.display="none";
				document.getElementById("smallapple5").style.display="none";
				document.getElementById("smallapple6").style.display="none";
			};
			//点设置的函数
             function shezhi(){
             	document.getElementById("shezhi_jiemian").style.display="block";
             	document.getElementById("bg").innerHTML=" ";
             numTo0();
             	document.getElementById("shezhi_jiemian").style.display="block";
             	pause();
            cancelAll();
            clear_apple();
             }
             function queding(){
             	var gameLV= (document.getElementById("LVnum").value)*1;
             	 winNum= document.getElementById("passNum").value;
             	 loseNum= document.getElementById("nopassNum").value;
             	 var nandu=document.getElementById("nandu");
             	 nandu.innerHTML=gameLV;
             	switch(gameLV){
             		case 1:
             		 appleNum=2000;
		              speed=100;
		              break;
		              case 2:
              		 appleNum=1400;
		              speed=60; 
		              break;
		              case 3:
             		 appleNum=1000;
		              speed=30;
		              break;
		              case 4:
             		 appleNum=600;
		              speed=10;
		              break;	
		              default:
		              alert("难度等级最高为4");
		              moren();
		            nandu.innerHTML=1;
		              break;
		               numTo0();
		               cancelAll();
		               
		               
             	}
             	
             	console.log(gameLV+"/"+speed+"/"+appleNum);
             	document.getElementById("shezhi_jiemian").style.display="none";
             	
             }
             function cancelAll(){
             	  rightNum=0;
              falseNum=0;
              document.getElementById("bg").innerHTML="";
             };
             function quxiao(){
             	document.getElementById("shezhi_jiemian").style.display="none"; 
             } ;
//           	 
             	function moren(){
             		document.getElementById("LVnum").value="1";
             		document.getElementById("passNum").value="50";
             		document.getElementById("nopassNum").value="50";
             	};

			function over() {
				history.go(0);
				clearInterval(sjks);
			};

			function pause() {
				clearInterval(id2);
				clearInterval(id1);
				id2=0;
				id1=0;
				id5=0;
				clearInterval(sjks);
			};
			function start() {	
				if(id1==0&&id2==0&&id3==0){
				id2 = setInterval("addapple()", appleNum);
				id1 = setInterval("appledown()", speed);
				if(id4==1){
					numTo0();
					id4=0; 
					clear_apple();
				}
				id5=1;
				 sjks= setInterval("showtime()",1000);
			}};
			
			function  showtime(){
				document.getElementById("right_sudu").innerHTML=parseInt(rightNum/miao*60);
				
				//点击开始后设置时间
				miao++;
				if (miao==60) {
					miao = 0;
					fen++;
					if (fen == 60) {
						fen = 0;
						shi++;
					}
				}
    var time =  document.getElementById("shijian")
    time.innerHTML= (shi<10?("0"+shi):shi)+":"+ (fen<10?("0"+fen):fen)+":"+(miao<10?("0"+miao):miao);
			};
			
			
function numTo0(){
  	document.getElementById("right_score").innerHTML="0";
             	document.getElementById("false_score").innerHTML="0";
             	document.getElementById("right_parsent").innerHTML="0";
}
			function appledown() {
				var bg = document.getElementById("bg");
				for (i = 0; i < bg.children.length; i++) {
					var t = parseInt(bg.children[i].style.top);
					t += 5;
					bg.children[i].style.top = t + "px";
					if (t > 390) {
						bg.children[i].setAttribute("class", "badapple");
						bg.children[i].innerHTML=" ";
					}
					if (t > 410) {
						bg.removeChild(bg.children[i]);
						falseNum++;
					document.getElementById("false_score").innerHTML=falseNum;
					rightlv=(rightNum/(rightNum+falseNum)).toFixed(2)*100;
						document.getElementById("right_parsent").innerHTML=rightlv;
						if(falseNum==loseNum){
							alert("哎呀！没有通关呀！");
							pause();
							cancelAll();
							id4=1;
							clear_apple();
						}
					}
				}
			}
       //创建苹果（div）
			function addapple() {
				//创建div
				var a = document.createElement("div");
				//这是26个英文字母的代码
				var num = parseInt(Math.random() * 26) + 65;
				var l = parseInt(Math.random() * 700);
				a.innerHTML = "&#" + num + ";";
				//设置属性值
				a.setAttribute("class", "apple");
				a.setAttribute("keycode", num);
				//设置创建苹果的起始化高度，宽，随机的出现
				a.style.left = l + "px";
				a.style.top = "0px";
				document.getElementById("bg").appendChild(a);
			} ;
			
			